var baseURL = "/knowledge/";
$(function () {
    /*项目路径*/
    var baseURL = /knowledge/
    totalSize = 0;
    var currentSize = 0

    /*构建列表*/
    $("#jqGrid").jqGrid({
        url: baseURL + 'owlManage/getOwlList',
        datatype: "json",
        colModel: [
            {label: '文件名称', name: 'fileName', index: "documentOrigin", width: 45, key: true},
            {label: '模型名称', name: 'fileName', width: 75},
            {label: '大小', name: 'fileSize', width: 90},
            {label: '创建时间', name: 'createTime', width: 100},
            {
                label: '操作', name: 'fileOwner', width: 80, formatter: function (value, options, row) {
                	var ModelName="";
                	ModelName = row.fileName+"";
                    //if (value == 0) {
                        return "<span class=\"label label-info\"  onclick=\"showOwl('"+ModelName+"')\">本体详情</span>";
                    //}
                    /*if (value == 1) {
                        return '<span class="label label-success">替换本体</span>';
                    }
                    if (value == 2) {
                        return '<span class="label label-danger">审核不过</span>';
                    }*/
                }
            },
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.pageNum",
            total: "page.pages",
            records: "page.total"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
})

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            key: null
        },
        showList: true,
        title: null,
        document: {
            documentUploadDate: null,
            documentAbstract: null
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData:{'key': vm.q.key},
                page: page
            }).trigger("reloadGrid");
        },
        add: function () {
        	vm.showList = false;
            vm.title = "新增";
        }
    }
});

function showOwl(ModelName){
	window.location.href=baseURL+"visual.html?ModelName="+ModelName;
}

$("#upload").click(function(){
	var fileId="owlFile";
	$.ajaxFileUpload({
		type:"post",
		url:baseURL+"/owlManage/uploadFile",
		dataType:"json",
		async:false,
		secureuri:false,
		fileElementId:fileId,
		success: function(data) {   //提交成功后自动执行的处理函数，参数data就是服务器返回的数据。
            alert(data);
            vm.showList = true;
        	vm.reload();
        },
        error: function(data, status, e) {  //提交失败自动执行的处理函数。
            console.error(e);
        }
		
	});
})

$("#cancel").click(function(){
	vm.showList = true;
	vm.reload();
})